package c.e.a.c.p;

import android.animation.TimeInterpolator;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.text.Layout.Alignment;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import b.i.i.d;
import b.i.k.o;
import c.e.a.c.q.a;
import java.util.Objects;
import java.util.WeakHashMap;

/* compiled from: CollapsingTextHelper */
public final class c {
    public float A;
    public float B;
    public int[] C;
    public boolean D;
    public final TextPaint E;
    public final TextPaint F;
    public TimeInterpolator G;
    public TimeInterpolator H;
    public float I;
    public float J;
    public float K;
    public ColorStateList L;
    public StaticLayout M;
    public float N;
    public float O;
    public float P;
    public CharSequence Q;
    public final View a;
    public boolean b;
    public float c;
    public final Rect d;
    public final Rect e;
    public final RectF f;
    public int g = 16;
    public int h = 16;
    public float i = 15.0f;
    public float j = 15.0f;
    public ColorStateList k;
    public ColorStateList l;
    public float m;
    public float n;
    public float o;
    public float p;
    public float q;
    public float r;
    public Typeface s;
    public Typeface t;
    public Typeface u;
    public a v;
    public CharSequence w;
    public CharSequence x;
    public boolean y;
    public Bitmap z;

    public c(View view) {
        this.a = view;
        TextPaint textPaint = new TextPaint(129);
        this.E = textPaint;
        this.F = new TextPaint(textPaint);
        this.e = new Rect();
        this.d = new Rect();
        this.f = new RectF();
    }

    public static int a(int i, int i2, float f) {
        float f2 = 1.0f - f;
        return Color.argb((int) ((((float) Color.alpha(i2)) * f) + (((float) Color.alpha(i)) * f2)), (int) ((((float) Color.red(i2)) * f) + (((float) Color.red(i)) * f2)), (int) ((((float) Color.green(i2)) * f) + (((float) Color.green(i)) * f2)), (int) ((((float) Color.blue(i2)) * f) + (((float) Color.blue(i)) * f2)));
    }

    public static float i(float f, float f2, float f3, TimeInterpolator timeInterpolator) {
        if (timeInterpolator != null) {
            f3 = timeInterpolator.getInterpolation(f3);
        }
        timeInterpolator = c.e.a.c.c.a.a;
        return c.b.a.a.a.a(f2, f, f3, f);
    }

    public static boolean l(Rect rect, int i, int i2, int i3, int i4) {
        return rect.left == i && rect.top == i2 && rect.right == i3 && rect.bottom == i4;
    }

    public float b() {
        if (this.w == null) {
            return 0.0f;
        }
        TextPaint textPaint = this.F;
        textPaint.setTextSize(this.j);
        textPaint.setTypeface(this.s);
        textPaint = this.F;
        CharSequence charSequence = this.w;
        return textPaint.measureText(charSequence, 0, charSequence.length());
    }

    public final boolean c(CharSequence charSequence) {
        View view = this.a;
        WeakHashMap weakHashMap = o.a;
        Object obj = 1;
        if (view.getLayoutDirection() != 1) {
            obj = null;
        }
        return ((b.i.i.d.c) (obj != null ? d.d : d.c)).b(charSequence, 0, charSequence.length());
    }

    public final void d(float f) {
        this.f.left = i((float) this.d.left, (float) this.e.left, f, this.G);
        this.f.top = i(this.m, this.n, f, this.G);
        this.f.right = i((float) this.d.right, (float) this.e.right, f, this.G);
        this.f.bottom = i((float) this.d.bottom, (float) this.e.bottom, f, this.G);
        this.q = i(this.o, this.p, f, this.G);
        this.r = i(this.m, this.n, f, this.G);
        p(i(this.i, this.j, f, this.H));
        float f2 = 1.0f - f;
        TimeInterpolator timeInterpolator = c.e.a.c.c.a.b;
        this.N = 1.0f - i(0.0f, 1.0f, f2, timeInterpolator);
        View view = this.a;
        WeakHashMap weakHashMap = o.a;
        view.postInvalidateOnAnimation();
        this.O = i(1.0f, 0.0f, f, timeInterpolator);
        this.a.postInvalidateOnAnimation();
        ColorStateList colorStateList = this.l;
        ColorStateList colorStateList2 = this.k;
        if (colorStateList != colorStateList2) {
            this.E.setColor(a(h(colorStateList2), g(), f));
        } else {
            this.E.setColor(g());
        }
        this.E.setShadowLayer(i(0.0f, this.I, f, null), i(0.0f, this.J, f, null), i(0.0f, this.K, f, null), a(h(null), h(this.L), f));
        this.a.postInvalidateOnAnimation();
    }

    public final void e(float f) {
        if (this.w != null) {
            Object obj;
            float width = (float) this.e.width();
            float width2 = (float) this.d.width();
            if ((Math.abs(f - this.j) < 0.001f ? 1 : null) != null) {
                f = this.j;
                this.A = 1.0f;
                Typeface typeface = this.u;
                Typeface typeface2 = this.s;
                if (typeface != typeface2) {
                    this.u = typeface2;
                    obj = 1;
                } else {
                    obj = null;
                }
            } else {
                float f2 = this.i;
                Typeface typeface3 = this.u;
                Typeface typeface4 = this.t;
                if (typeface3 != typeface4) {
                    this.u = typeface4;
                    obj = 1;
                } else {
                    obj = null;
                }
                if ((Math.abs(f - f2) < 0.001f ? 1 : null) != null) {
                    this.A = 1.0f;
                } else {
                    this.A = f / this.i;
                }
                f = this.j / this.i;
                width = width2 * f > width ? Math.min(width / f, width2) : width2;
                f = f2;
            }
            if (width > 0.0f) {
                obj = (this.B == f && !this.D && obj == null) ? null : 1;
                this.B = f;
                this.D = false;
            }
            if (this.x == null || r7 != null) {
                Object a;
                this.E.setTextSize(this.B);
                this.E.setTypeface(this.u);
                this.E.setLinearText(this.A != 1.0f);
                boolean c = c(this.w);
                this.y = c;
                try {
                    f fVar = new f(this.w, this.E, (int) width);
                    fVar.i = TruncateAt.END;
                    fVar.h = c;
                    fVar.e = Alignment.ALIGN_NORMAL;
                    fVar.g = false;
                    fVar.f = 1;
                    a = fVar.a();
                } catch (f.a e) {
                    Log.e("CollapsingTextHelper", e.getCause().getMessage(), e);
                    a = null;
                }
                Objects.requireNonNull(a);
                this.M = a;
                this.x = a.getText();
            }
        }
    }

    public float f() {
        TextPaint textPaint = this.F;
        textPaint.setTextSize(this.j);
        textPaint.setTypeface(this.s);
        return -this.F.ascent();
    }

    public int g() {
        return h(this.l);
    }

    public final int h(ColorStateList colorStateList) {
        if (colorStateList == null) {
            return 0;
        }
        int[] iArr = this.C;
        if (iArr != null) {
            return colorStateList.getColorForState(iArr, 0);
        }
        return colorStateList.getDefaultColor();
    }

    public void j() {
        boolean z = this.e.width() > 0 && this.e.height() > 0 && this.d.width() > 0 && this.d.height() > 0;
        this.b = z;
    }

    public void k() {
        if (this.a.getHeight() > 0 && this.a.getWidth() > 0) {
            float f = this.B;
            e(this.j);
            CharSequence charSequence = this.x;
            if (charSequence != null) {
                StaticLayout staticLayout = this.M;
                if (staticLayout != null) {
                    this.Q = TextUtils.ellipsize(charSequence, this.E, (float) staticLayout.getWidth(), TruncateAt.END);
                }
            }
            charSequence = this.Q;
            float f2 = 0.0f;
            float measureText = charSequence != null ? this.E.measureText(charSequence, 0, charSequence.length()) : 0.0f;
            int absoluteGravity = Gravity.getAbsoluteGravity(this.h, this.y);
            int i = absoluteGravity & 112;
            if (i == 48) {
                this.n = (float) this.e.top;
            } else if (i != 80) {
                this.n = ((float) this.e.centerY()) - ((this.E.descent() - this.E.ascent()) / 2.0f);
            } else {
                this.n = this.E.ascent() + ((float) this.e.bottom);
            }
            absoluteGravity &= 8388615;
            if (absoluteGravity == 1) {
                this.p = ((float) this.e.centerX()) - (measureText / 2.0f);
            } else if (absoluteGravity != 5) {
                this.p = (float) this.e.left;
            } else {
                this.p = ((float) this.e.right) - measureText;
            }
            e(this.i);
            StaticLayout staticLayout2 = this.M;
            measureText = staticLayout2 != null ? (float) staticLayout2.getHeight() : 0.0f;
            CharSequence charSequence2 = this.x;
            float measureText2 = charSequence2 != null ? this.E.measureText(charSequence2, 0, charSequence2.length()) : 0.0f;
            StaticLayout staticLayout3 = this.M;
            if (staticLayout3 != null) {
                f2 = staticLayout3.getLineLeft(0);
            }
            this.P = f2;
            int absoluteGravity2 = Gravity.getAbsoluteGravity(this.g, this.y);
            int i2 = absoluteGravity2 & 112;
            if (i2 == 48) {
                this.m = (float) this.d.top;
            } else if (i2 != 80) {
                this.m = ((float) this.d.centerY()) - (measureText / 2.0f);
            } else {
                this.m = this.E.descent() + (((float) this.d.bottom) - measureText);
            }
            int i3 = absoluteGravity2 & 8388615;
            if (i3 == 1) {
                this.o = ((float) this.d.centerX()) - (measureText2 / 2.0f);
            } else if (i3 != 5) {
                this.o = (float) this.d.left;
            } else {
                this.o = ((float) this.d.right) - measureText2;
            }
            Bitmap bitmap = this.z;
            if (bitmap != null) {
                bitmap.recycle();
                this.z = null;
            }
            p(f);
            d(this.c);
        }
    }

    public void m(ColorStateList colorStateList) {
        if (this.l != colorStateList) {
            this.l = colorStateList;
            k();
        }
    }

    public void n(int i) {
        if (this.h != i) {
            this.h = i;
            k();
        }
    }

    public void o(float f) {
        if (f < 0.0f) {
            f = 0.0f;
        } else if (f > 1.0f) {
            f = 1.0f;
        }
        if (f != this.c) {
            this.c = f;
            d(f);
        }
    }

    public final void p(float f) {
        e(f);
        View view = this.a;
        WeakHashMap weakHashMap = o.a;
        view.postInvalidateOnAnimation();
    }

    public void q(Typeface typeface) {
        Object obj;
        a aVar = this.v;
        boolean z = true;
        if (aVar != null) {
            aVar.c = true;
        }
        if (this.s != typeface) {
            this.s = typeface;
            obj = 1;
        } else {
            obj = null;
        }
        if (this.t != typeface) {
            this.t = typeface;
        } else {
            z = false;
        }
        if (obj != null || z) {
            k();
        }
    }
}
